
function all_playerLoader(params) {
    var that=this;
    this.isSupportH5=false
    this.playerType='flash';
    this.h5core='flvjs';//flvjs hls

    //====> 浏览器检测 =========================
    /*
    Due to IO restrictions, flv.js can support HTTP FLV live stream on Chrome 43+, FireFox 42+, Edge 15.15048+ and Safari 10.1+ for now.

    HTTP FLV live stream relies on stream IO, which has been introduced in fetch and stream spec. Now FetchStreamLoader works well on most of the modern browsers:

    Chrome: FetchStreamLoader works well on Chrome 43+
    FireFox: FireFox has fetch support but stream is missing, moz-chunked-arraybuffer xhr extension is used
    Edge: fetch + stream is broken on old version of Microsoft Edge, see Fetch API with ReadableStream has bug with data pumping. Got fixed in Creator Update (RS2).
    Safari: FetchStreamLoader works well since Safari 10.1 (macOS 10.12.4)
     */

    var _browser = {},
        sys = {},
        ua = navigator.userAgent.toLowerCase(),
        s;
    (s = ua.match(/edge\/([\d.]+)/)) ? sys.edge = s[1] :
        (s = ua.match(/rv:([\d.]+)\) like gecko/)) ? sys.ie = s[1] :
            (s = ua.match(/msie ([\d.]+)/)) ? sys.ie = s[1] :
                (s = ua.match(/firefox\/([\d.]+)/)) ? sys.firefox = s[1] :
                    (s = ua.match(/chrome\/([\d.]+)/)) ? sys.chrome = s[1] :
                        (s = ua.match(/opera.([\d.]+)/)) ? sys.opera = s[1] :
                            (s = ua.match(/version\/([\d.]+).*safari/)) ? sys.safari = s[1] : 0;

    if (sys.edge) _browser = { name : "edge", version : sys.edge };
    if (sys.ie) _browser = { name : "ie", version : sys.ie };
    if (sys.firefox) _browser = { name : "firefox", version : sys.firefox };
    if (sys.chrome) _browser = { name : "chrome", version : sys.chrome };
    if (sys.opera) _browser = { name : "opera", version : sys.opera };
    if (sys.safari) _browser = { name : "safari", version : sys.safari };
    _browser.version = parseFloat(_browser.version);



    //
    var ver=_browser.version


    console.log(_browser);
    //var ver=Number(jQuery.browser.version.substring(0, 2))
    if(_browser.name=="chrome"){
        if(ver>60&&ver<90){
            this.isSupportH5=true;
        }

    }else if(_browser.name=="safari"){
        if(ver>10){
            this.isSupportH5=true;
        }
    }
    else if(_browser.name=="firefox"){
        if(ver>42){
            this.isSupportH5=true;
        }
    }
    else if(_browser.name=="edge"){
        if(ver>15){
            this.isSupportH5=true;
        }
    }

    //---- palyerLoader 首选使用播放器类型
    if(params.fristPlayerType=='h5'){
        if(this.isSupportH5==true){
            this.playerType='h5';
        }else{
            this.playerType='flash';
        }

    }else if(params.fristPlayerType=='flash'){
        this.playerType='flash';
    }


    //===== homepage 判断支持flash 的首选flash =========
    if(params.mode=='homepage'||params.mode=='room'||params.mode=='audio'){
        if(hasUsableFlash()==false&&this.isSupportH5==true){
            this.playerType='h5';
        }
    }

    //----- 是否支持flash -----//
    function hasUsableFlash(){
        var flashObj;
        if(typeof window.ActiveXObject != "undefined"){
            flashObj= new  ActiveXObject("ShockwaveFlash.ShockwaveFlash");
        }else{
            flashObj= navigator.plugins['Shockwave Flash'];
        }
        return flashObj? true : false;
    }

    //===> 选择 h5 or flash 播放器 =============
    if(location.search.indexOf('h5test')>-1){
        if(this.isSupportH5==true){
            this.playerType='h5';
        }else{
            this.playerType='flash';
        }
    }else if(location.search.indexOf('flashtest')>-1) {
        this.playerType='flash';

    }
    else if(location.search.indexOf('h5hls')>-1) {
        this.h5core='hls';

    }




    //----- log -------//
    var showlog={
        params:params,
        type:this.playerType,
        isSupportH5:this.isSupportH5
    }
    //console.log('[PlayerLoader]==> ',showlog);
    //======= obj ==========================
    this.swfObj='//vj0.xiu123.cn/mini/js/base/swfobject_2016_3.js';
    // h5 flash 统一对象名
    this.player=null;

    //======== url =========================
    this.h5_player_url=null;
    this.flash_player_url=null;

    //使用 room_videos.tpl 值
    try{
        //------ h5  --------
        this.h5_player_url=__PLAYER.h5Base;
        if(this.h5core=='hls'){
            this.h5_player_url=__PLAYER.h5hls;
        }

        this.swf_NOF=__NOF;
        //----- flash -------
        switch (params.mode) {
            case 'audio':
            case 'room':
                this.flash_player_url=__PLAYER.base;
                break
            case 'homepage':
                this.flash_player_url=__PLAYER.homepage;
                break
            case 'activity':
                this.flash_player_url=__PLAYER.event;
                break
            case 'family':
                this.flash_player_url=__PLAYER.family;
                break
            default:
                this.flash_player_url==__PLAYER.base;
        };
    }catch (e) {
        console.log('没有加载 room_videos.tpl文件！以启用默认文件地址。');
    }
    //如果没加载到 room_videos.tpl 值
    if(typeof(__PLAYER) == "undefined"){
        //------ h5  --------
        this.h5_player_url='V6FlvPlayer.js';
        this.h5_player_url='//vj0.xiu123.cn/mini/js/h5_liveplayer/V6FlvPlayer_36.js';

        this.swf_NOF= '/apple/expressInstall.swf';
        //----- flash -------
        switch (params.mode) {
            case 'audio':
            case 'room':
                this.flash_player_url='//v.6.cn/apple/livePlayer/roomplayer/roomLivePlayer_7.1.swf'
                break
            case 'homepage':
                this.flash_player_url='//v.6.cn/apple/livePlayer/homepagePlayer/homepagePlayer_3.3.swf'
                break
            case 'activity':
                this.flash_player_url='//v.6.cn/apple/livePlayer/roomplayer/activityLivePlayer_2.6.swf'
                break
            case 'family':
                this.flash_player_url='//v.6.cn/apple/livePlayer/family/familyLivePlayer_1.7.swf'
                break
            default:
                this.flash_player_url=='//v.6.cn/apple/livePlayer/roomplayer/roomLivePlayer_7.1.swf'
                break;
        };
    }



    //----- init -------

    this.params = params
    this.videoId=params.videoId;
    //-- 记录父节点 -- 在romove()后需要重新建立//
    this._parent_El=jQuery('#'+that.videoId).parent();


    //console.log('[V6_HF_liveplayer]==> ','this.params=',this.params)

    //------------------

    if(typeof($LAB) == "undefined"){
        console.log('[V6_HF_liveplayer]==> ','没有 $LAB,请先引用 LAB.js ')
    }





    //==================================
}
all_playerLoader.prototype={

    //
    loadPlayer:function(_type){
        var that=this;

        if(_type){
            this.playerType=_type;
        }

        if(this.playerType=='h5'){
            //V6player.js 是否已加载
            if(typeof(V6player) == "undefined"){
                //没有加载 需要加载
                $LAB.script(that.h5_player_url).wait(function(){
                    that.player = createH5Player();
                     window[that.params.readyFun]();
                });
            }else{
                //已加载 直接new
                //console.log('[V6_HF_liveplayer]==> ','V6player -->exist!',that.h5_player_url)

                that.player = createH5Player();
                window[that.params.readyFun]();
            }
        }else{
            //swfobject.js 是否已加载
            if(typeof(swfobject) == "undefined"){
                $LAB.script(this.swfObj).wait(function(){
                    that.player = createFlashPlayer();
                   // console.log('[V6_HF_liveplayer]==> ','swfobject-->loadFinish')
                });

            }else{
                //swfobject.js 已加载
                that.player = createFlashPlayer();
                //console.log('[V6_HF_liveplayer]==> ','swfobject-->exist!');
            }

        }
        //----------flash替换 div id ----------------
        function createFlashPlayer() {
            //console.log('[V6_HF_liveplayer]==> ',that.flash_player_url)
            var swfParams=that.params;

            if(!document.getElementById(that.videoId)) {
                that._parent_El.append('<div id='+that.videoId+'></div>');
            }
            jQuery('#'+that.videoId).html('<div class="fInstall"><a href="https://get.adobe.com/cn/flashplayer/" target="_blank">请安装或者启用FLASH播放器</a></div>')
            // jQuery('#'+that.videoId).append('<style>'+'#'+that.videoId+' .fInstall { z-index: 200; position: absolute; left: 50%; top: 50%; width: 214px; height: 56px; margin: -28px 0 0 -107px; }'+"#"+that.videoId+' .fInstall a { display: block; width: 214px; height: 56px; line-height: 56px; background: #ff4443; border-radius: 3px; color: #fff; text-align: center; font-size: 14px; transition: all .35s ease-in-out 0s;text-decoration: none; cursor: pointer; } </style>')
            swfobject.embedSWF(that.flash_player_url, that.videoId, '100%', '100%', '10.1',this.swf_NOF,swfParams,{allowscriptaccess:'always', wmode:'Opaque', bgcolor:'#21201B'});
            var player = swfobject.getObjectById(that.videoId);
            return player;
        }
        function createH5Player() {
            var h5Params=that.params;

            var player =new V6player(h5Params)
            //console.log('[V6_HF_liveplayer]==> ','V6player -->loadFinish',that.h5_player_url)
            return player;
        }

    },
    getPlayer:function(){
        var that=this;

        return  this.player;
    },
    remove:function(){
        if(this.playerType=='h5'){
            this.player.remove();
            this.player=null;

        }else{
            try{
                var _element=document.getElementById(this.videoId);

                var _parentElement = _element.parentNode;
                if(_parentElement){
                    _parentElement.removeChild(_element);
                }

                //$('')
               // box.remove();
                this.player=null;
            }catch (e) {

            }

        }
        //console.log('all_playerLoader==> remove()')
    }
}

